﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bll;
using model;

public partial class Eedit : System.Web.UI.Page
{
    EnterpriseBll bll = new EnterpriseBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            string eno = Session["userid"].ToString();
            try
            {
                Enterprise enterprise = bll.GetSingle(eno);
                txtEno.Text = enterprise.Eno;
                txtEname.Text = enterprise.Ename;
                txtEintro.Text = enterprise.Eintro;

            }
            catch (Exception ex)
            {
                string js = "<script>alert('" + ex.Message + "');</script>";
                Response.Write(js);
            }
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            Enterprise enterprise = new Enterprise();
            enterprise.Eno = txtEno.Text;
            enterprise.Ename = txtEname.Text;
            enterprise.Eintro = txtEintro.Text;
            bll.Update(enterprise);
            Response.Write("<script>alert('修改成功！');location.href('Default.aspx');</script>");
        }
        catch (Exception ex)
        {
            string js = "<script>alert('" + ex.Message + "');</script>";
            Response.Write(js);
        }
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        bool valid = false;
        string ex = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
        string[] re = {".gif",".jpg","png",".bmg" };
        if (FileUpload1.HasFile)
        {
            for (int i = 0; i < re.Length; i++)
            {
                if (ex == re[i])
                {
                    valid = true;
                }
            }
        }
        if (valid == true)
        {
            try
            {
                FileUpload1.SaveAs(Server.MapPath("~/Pict/") + Session["username"].ToString() + ex);
                Label1.Text = "上传成功";
            }
            catch
            {
                Label1.Text = "上传不成功";
            }
        }
        else
        {
            Label1.Text = "只能上传gif,jpg,png,bmp文件";
        }
    }
}